package cn.sdhuijin.healthexam.activity;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RadioGroup;
import cn.sdhuijin.healthexam.ExitApplication;
import cn.sdhuijin.healthexam.R;
import cn.sdhuijin.healthexam.control.AbstractControlActivity;
import cn.sdhuijin.healthexam.util.Constants;

/**
 * 健康体检录入-第二页
 * 
 * @author houyuchun
 * 
 */
public class HealthExamFourthActivity extends AbstractControlActivity implements
		OnClickListener {

	private String createDate;
	private RadioGroup wlysfhcs;
	private RadioGroup hxwzfhcs;
	private RadioGroup qtfhcs;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_health_exam_fourth);
		ExitApplication.getInstance().addActivity(this);

		Intent intent = getIntent();
		Bundle bundle = intent.getBundleExtra("bundle");
		if (bundle != null) {
			createDate = bundle.getString("createDate");
		}
		setCurrentEditUserName(createDate);

		addRadioGroupView(R.id.rad_wlysfhcs, "物理因素防护措施");
		addRadioGroupView(R.id.rad_hxwzfhcs, "化学物质防护措施");
		addRadioGroupView(R.id.rad_qtfhcs, "其他防护措施");
		addRadioGroupView(R.id.rad_kouchun, "口唇");
		addRadioGroupView(R.id.rad_chilie, "齿列");
		addRadioGroupView(R.id.rad_yanbu, "咽部");

		addEditTextView(R.id.edt_zuoyanshili, "左眼视力");
		addEditTextView(R.id.edt_youyanshili, "右眼视力");
		addEditTextView(R.id.edt_zuoyanjzshili, "左眼矫正视力");
		addEditTextView(R.id.edt_youyanjzshili, "右眼矫正视力");

		addRadioGroupView(R.id.rad_tingli, "听力");
		addRadioGroupView(R.id.rad_yundonggongneng, "运动功能");
		addRadioGroupView(R.id.rad_yandi, "眼底");
		addRadioEditUnionView(new int[] { R.id.edt_gongmo_qita }, "巩膜",
				new String[] { "巩膜-其他" }, R.id.rad_gongmo, "其他");
		addRadioEditUnionView(new int[] { R.id.edt_pifu_qita }, "皮肤",
				new String[] { "皮肤-其他" }, R.id.rad_pifu, "其他");
		addRadioEditUnionView(new int[] { R.id.edt_linbajie_qita }, "淋巴结",
				new String[] { "淋巴结-其他" }, R.id.rad_linbajie, "其他");

		wlysfhcs = (RadioGroup) findViewById(R.id.rad_wlysfhcs);
		hxwzfhcs = (RadioGroup) findViewById(R.id.rad_hxwzfhcs);
		qtfhcs = (RadioGroup) findViewById(R.id.rad_qtfhcs);

		Properties properties = new Properties();
		File file = new File(Constants.PROPERTIES_PATH + createDate + ".txt");
		FileInputStream fileInputStream;
		try {
			fileInputStream = new FileInputStream(file);
			// 将属性文件流装载到Properties对象中
			properties.load(fileInputStream);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		controlManager.setPropertiesPath(Constants.PROPERTIES_PATH + createDate
				+ ".txt");
		if (properties.getProperty("职业病危害因素接触史").equals("无")) {
			wlysfhcs.check(R.id.rad_wlysfhcs_no);
			hxwzfhcs.check(R.id.rad_hxwzfhcs_no);
			qtfhcs.check(R.id.rad_qtfhcs_no);
		}
		controlManager.toControl();

		this.setButtonListener(this, R.id.btn_next, R.id.btn_previous);
	}

	/**
	 * 按钮点击处理事件
	 */
	@Override
	public void onClick(View arg0) {
		Intent intent = new Intent();
		Bundle bundle = new Bundle();
		// 获取点击按钮
		int id = (Integer) arg0.getId();
		switch (id) {
		case R.id.btn_previous:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			// 前一页按钮
			intent.setClass(this, HealthExamThirdActivity.class);
			startActivity(intent);
			this.finish();
			break;
		case R.id.btn_next:
			controlManager.toProperties();
			bundle.putString("createDate", createDate);
			// 创建日期
			intent.putExtra("bundle", bundle);
			intent.setClass(this, HealthExamFifthActivity.class);
			startActivity(intent);
			this.finish();
			break;
		default:
			break;
		}
	}

}
